{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "References:\n",
    "    - 轮廓系数的定义： https://blog.csdn.net/qq_19672707/article/details/106857918\n",
    "    - kmeans算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://blog.csdn.net/qq_19672707/article/details/106857918 轮廓系数\n",
    "#轮廓系数的计算\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.metrics import silhouette_score\n",
    "\n",
    "# 定义KMeans，以及K值\n",
    "kmeans = KMeans(n_clusters=n_clusters)\t\n",
    "# 根据数据data进行聚类，结果存放于result_list中\n",
    "result_list = kmeans.fit_predict(data)\n",
    "# 将原始的数据data和聚类结果result_list\n",
    "# 传入对应的函数计算出该结果下的轮廓系数\n",
    "score = silhouette_score(data, result_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "ad2bdc8ecc057115af97d19610ffacc2b4e99fae6737bb82f5d7fb13d2f2c186"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
